execute as @s[tag=!hasPower] at @s positioned ~ ~-1 ~ if entity @e[type=marker,nbt={Tags:["battery_box"]},distance=..1,limit=1,sort=nearest] if score @e[type=marker,nbt={Tags:["battery_box"]},distance=..1,limit=1,sort=nearest] advm_power matches 1.. run function advm:machines/wire_get_power_from_battery_box
execute as @s[tag=!hasPower] at @s positioned ~ ~-1 ~ if entity @e[type=marker,nbt={Tags:["burn_electricity_producer"]},distance=..1,limit=1,sort=nearest] if score @e[type=marker,nbt={Tags:["burn_electricity_producer"]},distance=..1,limit=1,sort=nearest] advm_power matches 1.. run function advm:machines/wire_get_power_from_battery_box
execute as @s[tag=!hasPower] at @s positioned ~ ~-1 ~ if entity @e[type=marker,nbt={Tags:["wind_electricity_producer"]},distance=..1,limit=1,sort=nearest] if score @e[type=marker,nbt={Tags:["wind_electricity_producer"]},distance=..1,limit=1,sort=nearest] advm_power matches 1.. run function advm:machines/wire_get_power_from_battery_box

execute as @s[tag=hasPower] run scoreboard players set @s advm_power 1
execute as @s[tag=!hasPower] run scoreboard players set @s advm_power 0

tag @s add finding

execute as @s[nbt={ItemRotation:1b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~1 ~ -1 if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:2b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~1 ~ ~ if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:3b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~1 ~ ~1 if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:4b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~0 ~ ~1 if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:5b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~-1 ~ ~1 if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:6b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~-1 ~ ~ if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:7b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~-1 ~ ~ if entity @s[tag=hasPower] run function advm:machines/wire_states_edit
execute as @s[nbt={ItemRotation:0b}] if score @s advm_power matches 1.. at @s positioned ~ ~ ~ align y run execute as @e[type=item_frame,distance=..1,limit=1,sort=nearest,nbt={Tags:["wire"]}] at @s positioned ~ ~ ~-1 if entity @s[tag=hasPower] run function advm:machines/wire_states_edit


tag @s remove finding